<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=1000, initial-scale=1.0, maximum-scale=1.0">
	    <!-- Loading Bootstrap -->
	    <link href="./Public/Admin/Flat/dist/css/vendor/bootstrap.min.css" rel="stylesheet">
	    <!-- Loading Flat UI -->
	    <link href="./Public/Admin/Flat/dist/css/flat-ui.css" rel="stylesheet">
	    <link href="./Public/Admin/Flat/docs/assets/css/demo.css" rel="stylesheet">
	    <link rel="shortcut icon" href="./Public/Admin/Flat/img/favicon.ico">
	    <script src="./Public/Admin/Flat/js/jquery-1.9.1.min.js" type="text/javascript" charset="utf-8"></script>
	    <!-- HTML5 shim, for IE6-8 support of HTML5 elements. All other JS at the end of file. -->
	    <!--[if lt IE 9]>
	      <script src="dist/js/vendor/html5shiv.js"></script>
	      <script src="dist/js/vendor/respond.min.js"></script>
	    <![endif]-->
	    <style type="text/css">
	    	.icon_my{
	    		margin-bottom: 2px;
	    		display: block;
	    		width: 150px;
	    	}
	    	
	    	.info_my{
	    		display: inline-block;
	    		width: 80%;
	    	}
	    	
	    	.label_my{
	    		width: 65px;
	    	}
	    	

	    	.file_info_my{
	    		display: inline-block;
	    		width: 80%;
	    	}
	    	
	    	input[type="file"]{
	    		display: inline-block;
	    		margin: 3px 2px;
	    		font-size: 14px;
	    		width: 100%;
	    		line-height: 60px;
	    	}
	    	
	    	.my_file_kk{
	    		width: 80%;
	    		display: inline-block;
	    		border: 2px solid #bdc3c7;
	    		border-radius: 6px;
	    		overflow: hidden;

	    	}
	    	
	    	.info_my_goodsattr{
	    		display: inline-block;
	    		width: 200px;
	    	}
	    	
	    	.label_my_goodsattr{
	    		width: 65px;
	    	}
	    	
	    	
	    	.info_my_goodsattr_atr{
	    		display: inline-block;
	    		width: 50%;
	    	}
	    	
	    	.label_my_goodsattr_atr{
	    		width: 65px;
	    	}
	    	
	    	.my_goods_attr{
	    		width: 350px;
	    		float: left;
	    	}
	    	
	    	#uploadList ul li{
	    		list-style-type: none;
	    		float: left;
	    		margin-left: 5px;
	    	}
	    	
	    	#uploadListP ul li{
	    		list-style-type: none;
	    		float: left;
	    		margin-left: 5px;
	    	}
	    	
	    </style>
	     <!--引入上传插件-->
	     <!-- 需要载入的文件 -->
	    <script type="text/javascript" src="./Public/uploadify/jquery-1.8.2.min.js"></script>
	    <script type="text/javascript" src="./Public/uploadify/jquery.uploadify.min.js"></script>
	    <link rel="stylesheet" type="text/css" href="./Public/uploadify/uploadify.css">
	    
	    <!--载入百度编辑器-->
	    	<script type="text/javascript" charset="utf-8" src="./Public/ueditor/ueditor.config.js"></script>
    		<script type="text/javascript" charset="utf-8" src="./Public/ueditor/ueditor.all.min.js"> </script>
    		<script type="text/javascript" charset="utf-8" src="./Public/ueditor/lang/zh-cn/zh-cn.js"></script>
	</head>
	<body>
		<form action="" method="post">
			    <a href="javascript:void(0)" class="btn btn-sm btn-primary icon_my">基本信息</a>
			    <!--所属分类-->
			    <div class="form-group">
					<label for="exampleInputEmail1" class="label_my">所属分类</label>
					<select name="sc_category_cid" class="form-control info_my" id="type_tid">
						<option value="0">请选择</option>
						<?php foreach ($CateData as $v){?>
						<option value="<?php echo $v['cid']?>" tid="<?php echo $v['sc_type_tid']?>" <?php if($v['cid']==$oldData['sc_category_cid']){?>
                selected="selected"
               <?php }?>><?php echo $v['_name']?></option>
						<?php }?>
					</select>
                    <input type="hidden" name="sc_type_tid" id="sc_type_tid" value="" />
				</div>
			    <!--所属分类结束-->
			    
			    
			    <!--所属品牌-->
			    <div class="form-group">
					<label for="exampleInputEmail1" class="label_my">所属品牌</label>
					<select name="sc_brand_bid" class="form-control info_my">
						<option value="0">请选择</option>
						<?php foreach ($BrandData as $v){?>
						<option value="<?php echo $v['bid']?>" <?php if($v['bid']==$oldData['sc_brand_bid']){?>
                 selected="selected" 
               <?php }?>><?php echo $v['bname']?></option>
						<?php }?>
					</select>
				</div>
			    <!--所属品牌结束-->
			    
			    <!--商品名称-->
				<div class="form-group">
					<label for="exampleInputEmail1" class="label_my">商品名称</label>
					<input id="exampleInputEmail1" class="form-control info_my" type="text" placeholder="请输入商品名称" required="" name="gname" value="<?php echo $oldData['gname']?>">
				    <input type="hidden" name="gid" id="gid" value="<?php echo $oldData['gid']?>" />
				</div>
				<!--商品名称结束-->
				
				 <!--商品货号开始-->
				<!--<div class="form-group">
					<label for="exampleInputEmail1" class="label_my">商品货号</label>
					<input id="exampleInputEmail1" class="form-control info_my" type="text" placeholder="请输入商品货号" required="" name="gnumber" value="<?php echo $oldData['gnumber']?>">
				</div>-->
				<!--商品货号结束-->
				
				<!--商品规格开始-->
				<div class="form-group">
					<label for="exampleInputEmail1" class="label_my">商品单位</label>
					<input id="exampleInputEmail1" class="form-control info_my" type="text" placeholder="请输入商品单位" required="" name="unit" value="<?php echo $oldData['unit']?>">
				</div>
				<!--商品规格结束-->
				
				<!--市场价-->
				<div class="form-group">
					<label for="exampleInputEmail1" class="label_my">市场价</label>
					<input id="exampleInputEmail1" class="form-control info_my" type="text" placeholder="请输入商品市场价" required="" name="marketprice" value="<?php echo $oldData['marketprice']?>">
				</div>
				<!--市场价结束-->
				
				<!--商品价-->
				<div class="form-group">
					<label for="exampleInputEmail1" class="label_my">商品价</label>
					<input id="exampleInputEmail1" class="form-control info_my" type="text" placeholder="请输入商品价" required="" name="shopprice" value="<?php echo $oldData['shopprice']?>">
				</div>
				<!--商品价结束-->
							
				<!--商品点击量-->
				<div class="form-group">
					<label for="exampleInputEmail1" class="label_my">点击量</label>
					<input id="exampleInputEmail1" class="form-control info_my" type="text" placeholder="请输入点击量" required="" name="click" value="<?php echo $oldData['click']?>">
				</div>
				<!--商品点击量结束-->
				
				<!--商品属性开始-->
                 <a href="javascript:void(0)" class="btn btn-sm btn-primary icon_my">商品属性</a>
			   
			    <div id="TypeAttr_class2">	
			    <!--商品属性结束-->
				    <div class="form-group">
				    	<?php foreach ($GoodsAttrData as $v){?>
				    	<?php if($v['class']==2){?>
                
						<div class="form-group">
							<label for="exampleInputEmail1" class="label_my_goodsattr_atr"><?php echo $v['taname']?></label>
								<select name="attr[<?php echo $v['taid']?>]" class="form-control info_my_goodsattr_atr">
									<option value="">请选择</option>
						                 <?php foreach ($v['tavalue'] as $value){?>
						                 <option value="<?php echo $value?>" <?php if($value==$v['gtvalue']){?>
                 selected="selected" 
               <?php }?>><?php echo $value?></option>

						                 <?php }?>
						            </select>
						            </div>
						   
               <?php }?>         
						<?php }?>
	               </div>	
			    </div>
			    
			    
			    <!--商品规格开始-->
                <a href="javascript:void(0)" class="btn btn-sm btn-primary icon_my">商品规格</a>
                <!--商品规格开始-->
                <div id="TypeAttr_class1">
                   <?php $taid=[]; ?>                   
                	<?php foreach ($GoodsAttrData as $v){?>
                	<?php if($v['class']==1){?>
                
                	<?php $taid[]=$v['taid']; ?>
                	<div class="form-group spec_clon">
						<div class="form-group my_goods_attr">
						<label for="exampleInputEmail1" class="label_my_goodsattr"><?php echo $v['taname']?></label>
						<select name="spec[value][<?php echo $v['taid']?>][]" class="form-control info_my_goodsattr">
				            <option value="">请选择</option>
							 <?php foreach ($v['tavalue'] as $value){?>       
						         <option value="<?php echo $value?>" <?php if($value==$v['gtvalue']){?>
                 selected="selected" 
               <?php }?>><?php echo $value?></option>
							  <?php }?>       
						</select></div>
                        <div class="form-group my_goods_attr">
                        <label for="exampleInputEmail1" class="label_my_goodsattr">附加价格</label>
						<input id="exampleInputEmail1" class="form-control info_my_goodsattr" type="text" placeholder="请输入附加价格" name="spec[added][<?php echo $v['taid']?>][]" <?php if(!empty($v['added'])){?>
                 value="<?php echo $v['added']?> 
               <?php }?>">
						</div>
					    <a href="#fakelink" class="btn btn-lg btn-info removeSpec goodsAttr<?php echo $v['taid']?>">删除规格</a>
					</div>
					
               <?php }?>
					<?php }?>	
                </div>
            <!--商品规格开始-->
            
            <?php 
            	//去除重复 
            	$taid=array_unique($taid);
            ?>
               <script type="text/javascript">
               	   var taid='<?php echo json_encode($taid) ?>';
               	   //把JS字符串转化成json对象
               	   taid=$.parseJSON(taid);
               	   //循环json
               	   $.each(taid,function(k,v){
               	   	$('.goodsAttr' + v).first().removeClass('btn-info removeSpec').addClass('btn-success spec_add').html('增加规格');
               	   })
               </script>
			 
			 <a href="javascript:void(0)" class="btn btn-sm btn-primary icon_my">列表图</a>   
			 <!--列表图开始-->
	        <div class="form-group">
				<label for="exampleInputEmail1" class="label_my">列表图</label>
				<div class="my_file_kk">
					<input id="f" class="file_info_my" type="file" name="pic">
				    <?php if($oldData['pic']!=''){?>
                 
				    <input type="hidden" name="oldpic" id="oldpic" value="<?php echo $oldData['pic']?>" />
				    
               <?php }?>
				    <div id="uploadList">
				        <ul>
				        	<?php if($oldData['pic']!=''){?>
                 
				           <li><img width="100px" src="<?php echo $oldData['pic']?>"/></li>
				            
               <?php }?>
				        </ul>
				    </div>
				</div>	
			</div>
    <script type="text/javascript">
            $(function() {
               $('#f').uploadify({
	                'formData'     : {//POST数据
	                    '<?php echo session_name();?>' : '<?php echo session_id();?>',
	                },
	                'fileTypeExts' : '*.jpg;*.png',
	                'swf'      : '<?php echo __PUBLIC__?>/uploadify/uploadify.swf',
	                'uploader' : '<?php echo U('upload')?>',//指定服务器上传的方法
	                'buttonText':'选择文件',
	                'fileSizeLimit' : '2000KB',
	                'uploadLimit' : 1,//上传文件数
	                'width':65,
	                'height':25,
	                'successTimeout':10,//等待服务器响应时间
	                'removeTimeout' : 0.2,//成功显示时间
	                'onUploadSuccess' : function(file, data, response) {
	                    //把php返回的数据转为json
	                    data=$.parseJSON(data);
	                    //获得图片地址
	                    var imageUrl = data.url;
	                    var li="<li>";
	                    li += "<img width=100 src='"+imageUrl+"'/>";
	                    li += "<input type='hidden' name='pic' value='"+data.path+"'/><a href='javascript:;' id='self-close'>X</a>";
	                    li += "</li>";
	                    $("#uploadList ul").prepend(li);
                }
            });

			//关闭图片
            var i = 1;
            $('#self-close').live('click',function(){
                $(this).parent('li').remove();
                i++;
                $('#f').uploadify('settings','uploadLimit',i);
            })
        });
    </script>	
			<!--列表图结束-->
			
			
			<a href="javascript:void(0)" class="btn btn-sm btn-primary icon_my">商品图册</a>   
			 <!--商品图册开始-->
		    <!--<input type="hidden" name="sc_goods_gid" id="sc_goods_gid" value="<?php echo $GoodsDetailData['sc_goods_gid']?>" />-->
	        <div class="form-group">
				<label for="exampleInputEmail1" class="label_my">商品图</label>
				<div class="my_file_kk">
					<input id="p" class="file_info_my" type="file">
					<?php foreach ($GoodsDetailData['big'] as $v){?>
					<?php if($v!=''){?>
                 
					<input type="hidden" name="oldDetPic[]" id="oldDetPic" value="<?php echo $v?>" />
				    
               <?php }?> 
				    <?php }?>
				<div id="uploadListP">
				   <ul>
				   	<?php foreach ($GoodsDetailData['big'] as $v){?>
				   	  <?php if($v!=''){?>
                 
				   	    <li><img width="100px" src="<?php echo $v?>"/></li>
				   	  
               <?php }?> 
				   <?php }?>
				   </ul>
				</div>
				</div>	
			</div>	
			
			    <script type="text/javascript">
            $(function() {
               $('#p').uploadify({
	                'formData'     : {//POST数据
	                    '<?php echo session_name();?>' : '<?php echo session_id();?>',
	                },
	                'fileTypeExts' : '*.jpg;*.png',
	                'swf'      : '<?php echo __PUBLIC__?>/uploadify/uploadify.swf',
	                'uploader' : '<?php echo U('upload')?>',//指定服务器上传的方法
	                'buttonText':'选择文件',
	                'fileSizeLimit' : '2000KB',
	                'uploadLimit' : 4,//上传文件数
	                'width':65,
	                'height':25,
	                'successTimeout':10,//等待服务器响应时间
	                'removeTimeout' : 0.2,//成功显示时间
	                'onUploadSuccess' : function(file, data, response) {
	                    //把php返回的数据转为json
	                    data=$.parseJSON(data);
	                    //获得图片地址
	                    var imageUrl = data.url;
	                    var li="<li>";
	                    li += "<img width=100 src='"+imageUrl+"'/>";
	                    li += "<input type='hidden' name='detBig[]' value='"+data.path+"'/><a href='javascript:;' id='self-close'>X</a>";
	                    li += "</li>";
	                    $("#uploadListP ul").prepend(li);
                }
            });

			//关闭图片
            var i = 1;
            $('#self-close').live('click',function(){
                $(this).parent('li').remove();
                i++;
                $('#p').uploadify('settings','uploadLimit',i);
            })
        });
    </script>	
			<!--商品图册结束-->
			
			
			
			<a href="javascript:void(0)" class="btn btn-sm btn-primary icon_my" id="goods">商品详细</a>   
			<div class="form-group" id="goods_main" style="display:none;">
					<!--调用百度编辑器-->
					<script id="editor" type="text/plain" style="width:100%;height:500px;" name="intro"><?php echo $GoodsDetailData['intro']?></script>
				    <script>
				        var ue = UE.getEditor('editor');
				    </script>
			</div>
			<script type="text/javascript">
				$(function(){
					$('#goods').click(function(){
						$('#goods_main').toggle();
					})
				})
			</script>
                
				<button class="btn btn-primary btn-block" type="submit"> 确定 </button>
		</form>
		<script type="text/javascript">
			$(function(){
				$('select[name=sc_category_cid]').change(function(){
					var tid=$('option:selected').attr('tid');
					$('#sc_type_tid').val(tid);
					$.ajax({
						type:"post",
						url:"<?php echo U('Goods/getAttr')?>",
						data:{t : tid},
						//确定返回数据类型
						dataType:'json',
						success:function(phpData){
							var attr='';
							var spec='';
							$.each(phpData, function(k,v) {
								
								if(v.class==2){//如果是属性
									attr += '<div class="form-group">';
									attr += '<label for="exampleInputEmail1" class="label_my_goodsattr_atr">'+v.taname+'</label>';
									attr += '<select name="attr['+v.taid+']" class="form-control info_my_goodsattr_atr">';
									attr += '<option value="">请选择</option>';
						                 $.each(v.tavalue,function(kk,vv){
						                 	attr += '<option value="'+vv+'">'+vv+'</option>';

						                 });
						            attr += '</select>';
						            attr += '</div>';	
								}else{
									spec += '<div class="form-group spec_clon">';
									spec += '<div class="form-group my_goods_attr">';
									spec += '<label for="exampleInputEmail1" class="label_my_goodsattr">'+v.taname+'</label>';
						            spec += '<select name="spec[value]['+v.taid+'][]" class="form-control info_my_goodsattr">';
						            spec += '<option value="">请选择</option>';
							            $.each(v.tavalue, function(kk,vv) {
							            	spec += '<option value="'+vv+'">'+vv+'</option>'
							            });
							        spec += '</select></div>';
                                    spec += '<div class="form-group my_goods_attr">'; 
                                    spec += '<label for="exampleInputEmail1" class="label_my_goodsattr">附加价格</label>';
							        spec += '<input id="exampleInputEmail1" class="form-control info_my_goodsattr" type="text" placeholder="请输入附加价格" name="spec[added]['+v.taid+'][]">';
							        spec += '</div>';
					                spec += '<a href="#fakelink" class="btn btn-lg btn-success spec_add">添加规格</a></div>';	
								}
							});
							
							$('#TypeAttr_class2').html(attr);
					        $('#TypeAttr_class1').html(spec);
						}						
					});	
				})	
				
				//点击规格
				$('.spec_add').live('click',function(){
					
					//找到当前的父级div
					var divObj=$(this).parents('div.spec_clon');
					
					//克隆一个
					var div=divObj.clone();
					div.find('.spec_add').html('删除规格').removeClass('btn-success spec_add').addClass('btn-info removeSpec');
					
					divObj.after(div);
				})
				
				$('.removeSpec').live('click',function(){
					$(this).parents('div.spec_clon').remove();
				})
	
			})
		</script>
		
		
		
		
		
	</body>
</html>
